package com.efuture.mutlithread;

/**
 * @ClassNAME ThreadInterrupted
 * @Description  Thread.Interrupt()方法的使用 该方法执行，会进入线程sleep方法catch异常里
 * 异常后的方法会继续执行
 * @Author zhaoshanshan
 * @Date 2021/9/10 12:07 上午
 * @Version 1.0
 */
public class ThreadInterrupt {

    public static void main(String[] args) {
        System.out.println("主线程开始执行");
        ThreadInterruptedTest t = new ThreadInterruptedTest();
        t.start();
        try {
            Thread.sleep(5000);
            t.interrupt();//调用该方法 t子线程会进入到catch方法终止线程睡眠
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("主线程执行完成");
    }
}
class ThreadInterruptedTest extends Thread{
    @Override
    public void run() {
        System.out.println("子线程开始执行");
        try {
            Thread.sleep(1000*60);//休眠一分钟
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("子线程执行完成");
    }
}